package cn.the.angry.resourcemanager;

import java.awt.Image;
import java.awt.image.BufferedImage;

import cn.the.angry.model.IDs;
import cn.the.angry.util.GraphicUtils;

public class ResourceManager {
	
	private static final ResourcePool resourcePool = new ResourcePool();
	
	public ResourceManager(){
		
	}
	
	//得到bufferedimage中的某个部分
	public static BufferedImage getImageClip(BufferedImage bufImage,int x,int y,int  width,int height){
		return bufImage.getSubimage(x, y, width, height);
	}
	
	public static BufferedImage getImageClip(int id,int x,int y,int  width,int height){
		switch(id){
		case IDs.INGAME_GROUNDS_1:
			return resourcePool.ingame_ground.getSubimage(x, y, width, height);
		case IDs.INGAME_PARALLAX_1:
			return resourcePool.ingame_parallx.getSubimage(x, y, width, height);
		case IDs.INGAME_SKIES_1:
			return resourcePool.ingame_skies.getSubimage(x, y, width, height);
		case IDs.CURSORS_SHEET_1:
			return resourcePool.cursor_sheet.getSubimage(x, y, width, height);
		case IDs.INGAME_BIRDS_1:
			return resourcePool.ingame_birds.getSubimage(x, y, width, height);
		case IDs.INGAME_BLOCKS_1:
			return resourcePool.ingame_blocks1.getSubimage(x, y, width, height);
		case IDs.INGAME_BLOCKS_2:
			return resourcePool.ingame_blocks2.getSubimage(x, y, width, height);
		case IDs.CUTSCENES:
			return resourcePool.cut_scenes.getSubimage(x, y, width, height);
		default:
			return null;
		}
	}
	
	
	/*private static BufferedImage inGameBirdsTranslucentBufferImage=null;
	private static BufferedImage getInGameBirdsTranslucentBufferImage()
	{
		if(inGameBirdsTranslucentBufferImage==null)
		{
			final Image b = resourcePool.ingame_birds;
			final BufferedImage bi = new BufferedImage(b.getWidth(null), b.getHeight(null), BufferedImage.TYPE_INT_ARGB);//(BufferedImage)ResourceManager.getCursorSheet();
			Graphics2D g2d=bi.createGraphics();
			final BufferedImage tbi=g2d.getDeviceConfiguration().createCompatibleImage(b.getWidth(null), b.getHeight(null), Transparency.TRANSLUCENT);
			g2d.dispose();
			g2d=tbi.createGraphics();
			g2d.drawImage(b, 0, 0, null);
			inGameBirdsTranslucentBufferImage=tbi;
		}
		
		return inGameBirdsTranslucentBufferImage;
	}*/
	
	
	//得到弹弓
	public static Image getSlingshotRightImage()
	{
		return GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 0, 0, 40, 200), 2);
	}
	
	public static Image getSlingshotLeftImage()
	{
		return GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 832, 0, 44, 130), 2);
	}
	
	//戴着皇冠的猪
	public static Image[] getPigKingImages()
	{
		final Image[] pidKingImages=new Image[9];
		pidKingImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 40,0,125,155), 3);
		pidKingImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,40,155,125,155), 3);
		pidKingImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,40,310,125,155), 3);
		pidKingImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,40,465,125,155), 3);
		pidKingImages[4]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,40,620,125,155), 3);
		pidKingImages[5]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,40,775,125,155), 3);
		pidKingImages[6]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,170,0,125,155), 3);
		pidKingImages[7]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,297,0,127,155), 3);
		pidKingImages[8]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,424,0,127,155), 3);
		return pidKingImages;
	}
	
	//长胡子的猪
	public static Image[] getMustachePigImages()
	{
		final Image[] mustachePigImages=new Image[9];
		mustachePigImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,170, 625, 125, 100), 3);
		mustachePigImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,170, 728, 125, 100), 3);
		mustachePigImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,168, 831, 125, 100), 3);
		mustachePigImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 155, 114, 100), 3);
		mustachePigImages[4]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,409, 155, 114, 100), 3);
		mustachePigImages[5]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,521, 155, 114, 100), 3);
		mustachePigImages[6]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 255, 114, 100), 3);
		mustachePigImages[7]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,732, 155, 112, 100), 3);
		mustachePigImages[8]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,844, 155, 110, 100), 3);
		return mustachePigImages;
	}
	
	//普通猪
	public static BufferedImage[] getNormalPigImages()
	{
		final BufferedImage[] normalPigImages=new BufferedImage[9];
//		normalPigImages[0]=getImageClip(resourcePool.ingame_birds, 936, 743, 48, 48);
		normalPigImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,407, 255, 101, 98), 3);
		normalPigImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,508, 255, 101, 98), 3);
		normalPigImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,609, 255, 101, 98), 3);
		normalPigImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,710, 255, 101, 98), 3);
		normalPigImages[4]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 355, 101, 98), 3);
		normalPigImages[5]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 454, 101, 98), 3);
		normalPigImages[6]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 553, 101, 98), 3);
		normalPigImages[7]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 652, 101, 98), 3);
		normalPigImages[8]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 847, 101, 98), 3);
		return normalPigImages;
	}
	
	//大的红鸟
	public static BufferedImage[] getLargeRedBirdImages()
	{
		final BufferedImage[] largeRedBirdImages=new BufferedImage[3];
//		largeRedBirdImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 902, 797, 48, 47), 2);
		largeRedBirdImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,295, 751, 100, 98), 3);
		largeRedBirdImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,632, 155, 100, 98), 3);
		largeRedBirdImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds,812, 255, 100, 98), 3);
		return largeRedBirdImages;
	}
	
	//大的木头球
	public static BufferedImage[] getLargeWoodBallImages()
	{
		final BufferedImage[] largeWoodBallImages=new BufferedImage[4];
		largeWoodBallImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,403, 123, 78, 76), 2);
		largeWoodBallImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,486, 123, 78, 76), 2);
		largeWoodBallImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,84, 445, 78, 76), 2);
		largeWoodBallImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,84, 523, 78, 76), 2);
		return largeWoodBallImages;
	}
	
	//正方形木头
	public static BufferedImage[] getMiddleWoodSquareImages()
	{
		final BufferedImage[] middleWoodSquareImages=new BufferedImage[4];
		middleWoodSquareImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,164, 918, 43, 43), 2);
		middleWoodSquareImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,164, 1004, 43, 43), 2);
		middleWoodSquareImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,164, 1133, 43, 43), 2);
		middleWoodSquareImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,224, 999, 43, 43), 2);
		return middleWoodSquareImages;
	}
	
	//长方形的木头
	public static BufferedImage[] getLargeWoodRectangleImages()
	{
		final BufferedImage[] largeWoodRectangleImages=new BufferedImage[4];
		largeWoodRectangleImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,711, 511, 84, 42), 2);
		largeWoodRectangleImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,881, 511, 84, 42), 2);
		largeWoodRectangleImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,224, 655, 84, 42), 2);
		largeWoodRectangleImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,224, 784, 84, 42), 2);
		return largeWoodRectangleImages;
	}
	
	//长条状的木头
	public static BufferedImage[] getLongWoodBattenImages()
	{
		final BufferedImage[] longWoodBattenImages=new BufferedImage[4];
		longWoodBattenImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 643, 206, 22), 2);
		longWoodBattenImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,516, 643, 206, 22), 2);
		longWoodBattenImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,723, 643, 206, 22), 2);
		longWoodBattenImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 665, 206, 22), 2);
		return longWoodBattenImages;
	}
	
	//还是木头
	public static BufferedImage[] getMiddleWoodBattenImages()
	{
		final BufferedImage[] middleWoodBattenImages=new BufferedImage[4];
		middleWoodBattenImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 732, 168, 20), 2);
		middleWoodBattenImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 798, 168, 20), 2);
		middleWoodBattenImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 864, 168, 20), 2);
		middleWoodBattenImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 930, 168, 20), 2);
		return middleWoodBattenImages;
	}
	
	//还是木头的说
	public static BufferedImage[] getShortWoodBattenImages()
	{
		final BufferedImage[] shortWoodBattenImages=new BufferedImage[4];
		shortWoodBattenImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 1018, 83, 20), 2);
		shortWoodBattenImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,395, 1040, 83, 20), 2);
		shortWoodBattenImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,310, 1084, 83, 20), 2);
		shortWoodBattenImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks1,395, 1106, 83, 20), 2);
		return shortWoodBattenImages;
	}
	
	//中等大小的木制长方形
	public static BufferedImage[] getMiddleWoodRectangleImages()
	{
		final BufferedImage[] middleWoodRectangleImages=new BufferedImage[4];
		middleWoodRectangleImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 835, 855, 41, 20), 2);
		middleWoodRectangleImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 835, 921, 41, 20), 2);
		middleWoodRectangleImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 920, 833, 41, 20), 2);
		middleWoodRectangleImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 1006, 877, 41, 20), 2);
		return middleWoodRectangleImages;
	}
	
	//小型的木制正方形
	public static BufferedImage[] getSmallWoodSquareImages()
	{
		final BufferedImage[] smallWoodRectangleImages=new BufferedImage[4];
		smallWoodRectangleImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 1048, 635, 20, 20), 2);
		smallWoodRectangleImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 1048, 679, 20, 20), 2);
		smallWoodRectangleImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 1048, 745, 20, 20), 2);
		smallWoodRectangleImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 1048, 811, 20, 20), 2);
		return smallWoodRectangleImages;
	}
	
	public static BufferedImage[] getMiddleWoodBallImages()
	{
		final BufferedImage[] middleWoodBallImages=new BufferedImage[4];
		middleWoodBallImages[0]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 452, 589, 40, 40), 2);
		middleWoodBallImages[1]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 452, 631, 40, 40), 2);
		middleWoodBallImages[2]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 452, 673, 40, 40), 2);
		middleWoodBallImages[3]=GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_blocks2, 452, 715, 40, 40), 2);
		return middleWoodBallImages;
	}
	
	public static BufferedImage getPigVictoryImage()
	{
		return getImageClip(resourcePool.cut_scenes, 0, 716, 446, 218);
	}
	
	public static BufferedImage getPigFailedImage()
	{
		return getImageClip(resourcePool.cut_scenes, 156, 1220, 617, 246);
	}
	
	//天空的背景
	public static BufferedImage getSkyImage()
	{
		return getImageClip(resourcePool.ingame_skies, 0, 0, 486, 318);
	}
	
	//树丛的背景
	public static BufferedImage getParallaxBackgroundImage()
	{
		return getImageClip(resourcePool.ingame_parallx, 0, 0, 480, 204);
	}
	
	//草丛的背景
	public static BufferedImage getParallaxGreenGroundImage()
	{
		return getImageClip(resourcePool.ingame_parallx, 0, 206, 335, 36);
	}
	
	//草地的背景
	public static BufferedImage getParallaxGrassImage()
	{
		return getImageClip(resourcePool.ingame_parallx, 0, 242, 446, 64);
	}
	
	//大地的背景
	public static BufferedImage getGroundImage()
	{
		return getImageClip(resourcePool.ingame_ground, 3, 2, 334, 191);
	}
	
	//建筑材料
	public static BufferedImage getGroundMaterialImage()
	{
		return resourcePool.ingame_theme_ground1;
	}
	
	//爆炸动画
	public static BufferedImage[] getBombImage(){
		final BufferedImage[] bombImages = new BufferedImage[4];
		bombImages[0] = GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 840, 442, 88, 85), 2);
		bombImages[1] = GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 170, 513, 116, 112), 2);
		bombImages[2] = GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 170, 278, 125, 122), 2);
		bombImages[3] = GraphicUtils.zoomOut(getImageClip(resourcePool.ingame_birds, 169, 154, 129, 125), 2);
		return bombImages; 
	}
	
	//空中运动的云朵
	public static BufferedImage[] getMovingCloudImage(){
		final BufferedImage[] movingCloudImages = new BufferedImage[5];
		movingCloudImages[0] = getImageClip(resourcePool.ingame_birds, 28, 811, 13, 13);
		movingCloudImages[1] = getImageClip(resourcePool.ingame_birds, 21, 799, 13, 13);
		movingCloudImages[2] = getImageClip(resourcePool.ingame_birds, 16, 767, 15, 15);
		movingCloudImages[3] = getImageClip(resourcePool.ingame_birds, 19, 731, 18, 18);
		movingCloudImages[4] = getImageClip(resourcePool.ingame_birds, 1, 344, 35, 35);
		return movingCloudImages; 
	}
	
}
